import pygame, sys, math, random

#Credit to Jared Midget, Comet Game

class Powerup():
    def __init__(self, pos):
        types = ["Speed", "Shield", "NoLight"]
        self.type = types[random.randint(0, len(types)-1)]
        if self.type == "Speed":
            self.image = pygame.image.load("rsc/Power Ups/speed up.png")
        elif self.type == "Shield":
            self.image = pygame.image.load("rsc/Power Ups/shield.png")
        elif self.type == "NoLight":
            self.image = pygame.image.load("rsc/Power Ups/flash light.png")
        #self.image = pygame.transform.scale(self.image, [25,25])
        self.rect = self.image.get_rect()
        self.place(pos)
        self.radius = self.rect.width/2
        self.living = True
        self.lifetime = 60 * 10
        
    def place(self, pos):
        self.rect.center = pos
    
    def update(self):
        #print self.lifetime
        if self.lifetime > 0:
            self.lifetime -= 1
        else:
            self.living = False
    
    def collidePlayer(self, other, darkness):
        if self.rect.right > other.rect.left and self.rect.left < other.rect.right:
            if self.rect.bottom > other.rect.top and self.rect.top < other.rect.bottom:
                self.living=False
                if self.type == "Speed":
                    other.speedUp()
                elif self.type == "Shield":
                    other.shield()
                elif self.type == "NoLight":
                    darkness.lightup()

                
    def collideEnemy(self, other):
        if self.rect.right > other.rect.left and self.rect.left < other.rect.right:
            if self.rect.bottom > other.rect.top and self.rect.top < other.rect.bottom:
                self.living=False
                 
                   
    def distanceToPoint(self, pt):
        x1 = self.rect.center[0]
        y1 = self.rect.center[1]
        x2 = pt[0]
        y2 = pt[1] 
    